function [A, b] = GetAffineMatrix2(IDx, IDy, Ix, Iy)

%%
%initialize affine transform parameters
A = zeros(2,2);
b = zeros(2,1);
Ab = zeros(6,1);

%ID and Ixy are (n x 2) matrix
bind  = find(IDx==0 & IDy ==0 & Ix ==0 & Iy == 0);
IDx(bind) = [];
IDy(bind) = [];
Ix(bind) = [];
Iy(bind) = [];

pointSize = length(IDx);
A = zeros(pointSize*2, 6);
B = zeros(pointSize*2, 1);

for i = 1:pointSize
    A(2*i-1,:) = [IDx(i) IDy(i) 0 0 1 0];
    A(2*i,:) = [0 0 IDx(i) IDy(i) 0 1];
    B(2*i-1) = Ix(i);
    B(2*i) = Iy(i);    
end


%%
%solve linear system
%if(det(Am)~=0)
%Aminv = inv(Am);
%end
%Ab = Bm'*Aminv;
%Ab = Bm'/Am;
%this solution can get perfect translation value only
Ab = A\B;
%Ab = (pinv(Am)*Bm)';
%Ab = linsolve(Am,Bm);
A = [Ab(1) Ab(2); Ab(3) Ab(4)];
b = [Ab(5) Ab(6)];
